package com.atguigu.lease.web.admin.custom.converter;

import com.atguigu.lease.model.enums.ItemType;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;

/**
 * @Author 快点干早点散
 * @Create 2025/3/26 19:35
 * Description:
 */
//@Component
public class StringToItemTypeConverter implements Converter<String, ItemType> {
    @Override
    public ItemType convert(String source) {
        //获取枚举的所有值
        ItemType[] values = ItemType.values();
        for (ItemType value : values) {
            if (source.equals(value.getCode() + "")) {
                return value;
            }
        }
        throw new RuntimeException("传入参数类型异常只能传入1,2");

    }
}
